/**
 * Created by LeungZ on 2016/8/15.
 */
class NodeSrv {
    constructor(commonSrv) {
        "ngInject";
        this._commonSrv = commonSrv;
    }

    getNodeList(para,filter) {
        return this._commonSrv('get', '/ctg-imageconsole-web/k8snode/queryNodes', {
            perpage: para.perPage || 10,
            page: para.page,
            nodeip: filter && filter.name,
            groupId: filter && filter.groupCode,
            clusterCode: para.code
        });
    }

    getNodeDetail(para) {
        return this._commonSrv('get', '/ctg-imageconsole-web/k8snode/queryNodeDetail',{
            nodeip: para.ip,
            clusterCode: para.code
        });
    }

    getNodesResource(para){
        return this._commonSrv('post', '/ctg-imageconsole-web/k8snode/queryNodesByIps',{
            ips:para.ips,
            clusterCode: para.code
        });
    }

    getNodeResource(para) {
        return this._commonSrv('get', '/ctg-imageconsole-web/k8snode/queryNodeResource',{
            nodeip: para.ip,
            clusterCode: para.code
        });
    }

    startNode(para){
        return this._commonSrv('post', '/ctg-imageconsole-web/k8snode/startOrShutdownNode',{
            nodeip: para.ip,
            unschedulable: false,
            clusterCode: para.code
        });
    }

    stopNode(para){
        return this._commonSrv('post', '/ctg-imageconsole-web/k8snode/startOrShutdownNode', {
            nodeip: para.ip,
            unschedulable: true,
            clusterCode: para.code
        });
    }

    //--------------------------------------组------------------------------------

    getGroupList(para,filter) {
        return this._commonSrv('get', '/ctg-imageconsole-web/dms/group/list', {
            pageSize: para.perPage || 10,
            pageNum: para.page,
            k8sCode: para.code,
            groupCode: filter && filter.name
        });
    }

    saveGroup(para){
        return this._commonSrv('post', '/ctg-imageconsole-web/dms/group/create', {
            groupCode: para.name,
            k8sCode: para.code,
            nodeList: para.nodes
        });
    }

    updateGroup(para){
        return this._commonSrv('post', '/ctg-imageconsole-web/dms/group/update', {
            id: para.id,
            groupCode: para.name,
            nodeList: para.nodes
        });
    }

    deleteGroup(id){
        return this._commonSrv('post', '/ctg-imageconsole-web/dms/group/delete', {
            id: id
        });
    }
}
export default NodeSrv